package condominio.servlet.cuota;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import condominio.excepcion.DAOExcepcion;
import condominio.negocio.GestionCuotas;

/**
 * Servlet implementation class CuotaInsertarServlet
 */
@WebServlet("/CuotaInsertarServlet")
public class CuotaInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public CuotaInsertarServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String a = request.getParameter("vivienda");
		String x = request.getParameter("fecha");
		String y = request.getParameter("estado");
		String w = request.getParameter("importe");
		String z = request.getParameter("periodo");
		
		GestionCuotas negocio = new GestionCuotas();
		try {
			negocio.insertar(a, x , y, w, z);
			response.sendRedirect(request.getContextPath()	+ "/CuotaNuevo.jsp");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}
